package com.docman.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

import com.docman.dbconnect.ConnectionManager;
import com.docman.domainmodel.DepartmentBean;


public class DepartmentDAO {

	static Connection currentCon = null;
	static ResultSet rs = null;
	
	public static ArrayList<DepartmentBean> getDepartments() {
		ArrayList<DepartmentBean> departments = new ArrayList<DepartmentBean>();
	
		String query = "SELECT * FROM department";
		
		try{
			
			currentCon =ConnectionManager.getInstance().getConnection();
			Statement stmt  = currentCon.prepareStatement(query);
			
			rs= stmt.executeQuery(query);
			
			while(rs.next()){
				DepartmentBean dept = new DepartmentBean();
				
				dept.setDepartmentName(rs.getString("deptName"));
				
				departments.add(dept);
				
			}
			
			rs.close();
			stmt.close();
		
		}
		catch(Exception e){
			
			System.out.println("Getting departments Failed :"+e);
		}
		
	
		return departments;
	}

}
